<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="head.jsp"%>
<%
	String id = request.getParameter("id");
	id = id == null ? "create" : id;
	
	String projectId = request.getParameter("projectId");
%>
<input type="hidden" id="id_id" value="<%=id%>">


<div class="am-cf admin-main">
	<!-- content start -->
	<div class="admin-content">
		<div class="admin-content-body">
			<div class="am-cf am-padding am-padding-bottom-0">
				<div class="am-fl am-cf">
					<strong class="am-text-primary am-text-lg">构建项目</strong> / <small>选择生成项目</small>
				</div>
			</div>
			<hr>

			<div class="am-g">
				<div class="am-u-sm-12 ">
					<form class="am-form " data-am-validator>
						<div class="am-form-group am-fr">
							<button type="button" id="id_project_batch_save" class="am-btn am-btn-primary">全部默认保存</button>
							<button type="button" id="id_project_save" class="am-btn am-btn-primary">保存修改</button>
							<!-- <button type="button" id="id_project_next" class="am-btn am-btn-primary">下一步</button> -->
						</div>
						<table class="am-table am-table-striped am-table-hover table-main">
							<thead>
								<tr>
									<th class="table-title">序号</th>
									<th class="table-title">表名称</th>
									<th class="table-title">对象名称</th>
									<th class="table-title">资源名称</th>
									<th class="table-title">修改时间</th>
									<th class="table-title">是否存在</th>
									<th class="table-author am-hide-sm-only">选择</th>
								</tr>
							</thead>
							<tbody id="id_tb_body">
							</tbody>
						</table>
						<hr>
						<p>说明：请确保所有表都编辑了生成选项</p>

					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	$(function() {
		loadData();
		$("#id_project_batch_save").on("click", function() {
			batchAddData();
		});
	});

	function loadData() {
		$.get("mvc/stable/list?id=" + $("#id_id").val(), function(data) {
			if (data && data.success) {
				filltr(data.data);
			} else {
				alert(data.message);
			}
		});
	}

	function filltr(data) {
		data = data || [];
		$("#id_tb_body").html("");
		var i=1;
		for ( var idx in data) {
			var context = "";
			var prj = data[idx];
			
			context +="<td>"+i+"</td><td> <a href='#'>" + prj['tableName'] + "</a></td>"
					+ '<td>' + prj['objectName'] + "</td>"
					+ '<td>' + prj['menuName'] + "</td>"
					+ '<td>' + prj['updateTime'] + "</td>";
			if(prj['isExists']==2){
				context +="<td style='background-color: green'></td>";
			}else{
				context +="<td style='background-color: red'></td>";
			}
			context += "<td>"
					+ '<a class="am-btn am-btn-default am-btn-xs am-hide-sm-only" href="htmloperation.jsp?id='
					+ prj['bizId'] + '&tableName=' + prj['tableName'] + '&projectId=' + '<%=projectId%>'
					+ '"><span class="am-icon-pencil-square-o"></span>编辑生成选项</a> '
					+ '<a class="am-btn am-btn-default am-btn-xs am-hide-sm-only"  href="javascript:deleteprj('
					+ prj['id']
					+ ')"><span class="am-icon-trash-o"></span>删除</a>'
					+ '<a class="am-btn am-btn-default am-btn-xs am-hide-sm-only"  href="javascript:saveTableHtml('
					+ "'"+prj['tableName']+"'"
					+ ')"><span class="am-icon-trash-o"></span>保存单表</a>'
					+ "</td>";

			context = "<tr>" + context + "</tr>";
			$("#id_tb_body").append(context);
			i++;

		}
	}

	function deleteprj(id) {
		$.get("mvc/stable/delete?id=" + id, function(data) {
			loadData();
		});
	}
	
	
	function saveTableHtml(tableName) {
		$.get("mvc/stable/saveHtmlProjectData?bizId=" + $("#id_id").val()+"&tableName="+tableName, function(data) {
			if (data && data.success) {
				alert(data.message);
				loadData();
			} else {
				alert(data.message);
			}
		});
	}
	
	function batchAddData(){
		alert("开发ing");
	}
</script>

<%@include file="bottom.jsp"%>